<?php
   //第一步：连接数据库
   require 'db_conn.php';//如果这个文件不存在，则程序终止
   //第二步：写查询语句并执行
   $sql="select * from db_employee";
   $pagesize=7;//每一页多少条
      	 $page=isset($_GET['page'])?($_GET['page']):1;
          $f=($page-1)*$pagesize;
   
      
      if(isset($_GET['searche']))
      	{
      	//按条件搜索	
      	$s=$_GET['searche'];
      	     $sqlzong="select*from db_employee  where name like '%{$s}%' ";
      		   $rs=$db->query($sqlzong);	 
      			$num=$rs->num_rows;//有条件留言总数
      		// 求页数		
      	$pagesum=ceil($num/$pagesize);	
      				
      		$sql="select * from db_employee where name like '%{$s}%'  order by id desc  limit $f,$pagesize";
      	} 
      	 else{  
             $sqlzong="select*from db_employee";
      	   $rs=$db->query($sqlzong);	 
      		    $num=$rs->num_rows;//留言总数
         $sql="select * from db_employee order by id desc limit $f,$pagesize";
         }
   $rs=$db->query($sql);
   //第三步：处理结果集，取结果集的行数，留言板表有多少条留言
//$num=$rs->num_rows;
   $emp=$rs->fetch_all(MYSQLI_BOTH);
   $rs->free_result();//结果集清除
   $db->close();//关闭数据库
?>
<?php $password=123456;?>

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>员工管理系统</title>
	<link rel="stylesheet" href="css/bootstrap.css">
	<script src="js/jquery-3.4.1.js"></script>
	<script src="js/bootstrap.js"></script>
	<style>
		#from{padding: 20px;width: 35%;height: auto;background-color: rgb(91,192,222);margin: auto;border-radius: 10px;}
#from input{width: 300px;line-height: 25px;}
#style input{width: 50px;}
#sub{text-align: center;margin: 15px 0 0 0;}
#line td{line-height: 50px;text-align: center;}
#center th{text-align: center;}
	</style>

</head>
<body>
	<div class="container">
		<h1 class="text-center">员工信息列表</h1>
		<h4>一共有<?php echo $num; ?>人,共分为<?php 	$pagesum=ceil($num/$pagesize);	  echo $pagesum; ?>页</h4>
		  <form action="" method="get" id="center" style="text-align: center;">
						<div class="input-group col-nd-3" style="margin-top:0px positon:relative">
						<input type="text"  name="searche" class="form-control"placeholder="请输入字段名" value="<?php echo isset($_GET['searche'])?$_GET['searche']:""; ?>"/>
						<span class="input-group-btn">
						<button class="btn btn-info btn-search" type="submit" onclick="show();">查找</button>
						<button class="btn btn-info btn-search" type="submit" value="提交" onclick="show();">23545</button>
						<script>
						function onclick(){
							alert($searche);
						}
						</script>
						</div>
				  		  </form>
		<table class="table table-bordered table-hover" >
			<tr id="center">
				<th >编号</th>
				<th>姓名</th>
				<th>头像</th>
				<th>所属部门</th>
				<th>出生日期</th>
				<th>入职日期</th>
				<th>操作</th>
			</tr>
			<?php foreach ($emp as $v)
			{
				?>
			<tr id="line">
				<td><?php echo $v['id']; ?></td>
				<td><?php echo $v['name']; ?></td>
				<td><img src="<?php echo $v['img']; ?>"></td>
				<td><?php echo $v['dep']; ?></td>
				<td><?php echo $v['f_date']; ?></td>
				<td><?php echo $v['l_date']; ?></td>
				<td>
					<a class="btn btn-danger" class="edit_a" href="bbsupdate.php?id=<?php echo $v['id']?>">编辑</a>
					<!-- <input type="button" class="btn btn-danger" class="edit_a" href="bbsupdate.php?id=<?php echo $v['id']?>" value="编辑" /> -->
					<input type="button" class="btn btn-danger" class="delete" href="javascript:" onclick="if(confirm('确定删除吗？')) 
					location.href='bbsdel.php?id=<?php echo $v['id']?>'" value="删除" />
				</td>
			</tr>
			<?php } ?>
		</table>
	</div>
	<div style="width: 10%;height: auto;position:fixed;position: absolute;top: 700px;left: 20%;">
				<ul class="pagination">
				    <li><a href="index.php">&laquo;</a></li>
					<?php
				$s=isset($_GET['searche'])?trim($_GET['searche']):'';
				for($i=1;$i<=$pagesum;$i++)
				{
				?>
			    <li><a href="index.php?page=<?php echo $i;?>&searche=<?php echo $s;?>"><?php echo $i;?></a></li>
			    <?php
				}
				echo "<script>";
				echo"function show(){ alert('$searche');}";
				echo"</script>";
				?>
				    <li><a href="#">&raquo;</a></li>
				</ul>
				</div>
	<div id="from">
	<form action="bbsadd.php" method="POST">
	<p>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：<input type="text" name="name"></p>
	<p>部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门：<input type="text" name="dep"></p>
				<p id="style">头&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;像:
				<input type="radio" name="img" value="images/1.jpg" checked="checked" /><img src=" images/1.jpg" alt="" />
				<input type="radio" name="img" value="images/2.jpg" /><img src=" images/2.jpg" alt="" />
				<input type="radio" name="img" value="images/3.jpg" /><img src=" images/3.jpg" alt="" />
				<input type="radio" name="img" value="images/4.jpg" /><img src=" images/4.jpg" alt="" />
			</p>
		<p>出生年月：<input type="date" name='f_date'></p>
		<p>入职时间：<input type="date" name='l_date'></p>
		<p id="sub">
		<button type="submit" class="btn btn-default">保存资料</button>
		<button type="submit" class="btn btn-default">重新填写</button>
	</p>
	</form>
	
</div>
	
</body>
</html>